package com.suray.wcs.service.pojo.rgv.extract.log;

import com.suray.basic.wcs.utils.LoggerUtil;
import com.suray.wcs.res.enums.RgvStatus;
import com.suray.wcs.service.pojo.Rgv;
import com.suray.wcs.service.pojo.rgv.extract.log.process.RgvExtractLogProcess;
import com.suray.wcs.service.util.WcsUtil;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class RgvExtractLog {
    public static volatile Set<Rgv> extractRgvs = new HashSet<>();

    /**
     * 开始提取日志
     * @param rgv
     * @param logName
     */
    public static synchronized void extractLog(Rgv rgv, String logName) throws IOException {
        extractRgvs.add(rgv);
        RgvStatus rgvStatus = rgv.getRgvStatus();
        try {
            rgv.setRgvStatus(RgvStatus.EXTRACT_LOG);
            new RgvExtractLogProcess(rgv, logName).start();
        } finally {
            try {
                rgv.setRgvStatus(rgvStatus);
                extractRgvs.remove(rgv);
            } catch (Exception e) {
                LoggerUtil.info("当前没有小车在提取日志", RgvExtractLog.class);
                WcsUtil.exceptionLog(e, RgvExtractLog.class);
            }
        }
    }
}
